package com.wzy.controller;

import com.wzy.pojo.Child;
import com.wzy.service.ChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@Controller
@RequestMapping(value="/child")
public class ChildController {
    @Autowired
    private ChildService childService;
    @RequestMapping
    public String Hello(Model model){
        List<Child> childList= childService.findAllChild();
        model.addAttribute("childList",childList);
        return "success";
    }

    @RequestMapping("addChildPage")
    public String addChild(){
        return "addChild";
    }

    @RequestMapping("addChild")
    public String addChild1(Child child, Model model){
        if(childService.addChild(child)){
            return "redirect:/child";
        }else {
            model.addAttribute("addChildPage", "没有找到孩子的父母");
            return "addChild";
        }
    }
    @RequestMapping("/updateChild")
    public String updateChild(Child child){
        childService.updateChild(child);
        return "redirect:/child";
    }

    @RequestMapping("/deleteChild")
    public String deleteChild(String ID){
        childService.deleteChild(ID);
        return "redirect:/child#student";
    }
}
